//
//  AFUserHelper.m
//  AFChat
//
//  Created by Void on 2018/6/20.
//  Copyright © 2018年 afei. All rights reserved.
//

#import "AFUserHelper.h"

@implementation AFUserHelper
@synthesize user = _user;

+ (AFUserHelper *)sharedHelper {
    
    static AFUserHelper *helper;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        helper = [[AFUserHelper alloc] init];
    });
    return helper;
}
- (void)loginTestAccount {
    AFUser *user = [[AFUser alloc] init];
    user.userID = @"1000";
    user.avatarURL = @"http://p1.qq181.com/cms/120506/2012050623111097826.jpg";
    user.nikeName = @"阿飞";
    user.userName = @"a-fei";
    
    [self setUser:user];
}

- (void)setUser:(AFUser *)user {
    _user = user;
    
    [[NSUserDefaults standardUserDefaults] setObject:user.userID forKey:@"loginUid"];
}

- (AFUser *)user {
    if (!_user) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"loginUid"];
    }
  return _user;
}

- (NSString *)userID {
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"loginUid"];
}
- (BOOL)isLogin {
    return self.user.userID.length > 0;;
}

@end
